package plan

import (
	"autoclave/model"
	"fmt"
	"math/rand"
	"time"
)

func Run() {
	go func() {
		for {
			// todo

			time.Sleep(5 * time.Second)
		}
	}()
	fmt.Println("plan is running")
}

type TaskInfo struct {
	State        int8 // 0.未开始 1.已开始
	SuccessTimes int
	FailTimes    int
	LastError    string
	StartTime    string
	EndTime      string
	Interval     int
}

var Task1 TaskInfo

func GenerateData() {
	for {
		rand.Seed(time.Now().UnixNano())
		if Task1.State == 0 {
			fmt.Println("GenerateData 已停止")
			return
		} else {
			param := model.PointFull{}
			param.MTemp = rand.Float64() * 100
			param.STemp = rand.Float64() * 100
			param.MPressure = rand.Float64() * 100
			param.SPressure = rand.Float64() * 100
			param.MVacuo = rand.Float64() * 100
			param.SVacuo = rand.Float64() * 100
			param.Tc1 = rand.Float64() * 100
			param.Tc2 = rand.Float64() * 100
			param.Tc3 = rand.Float64() * 100
			param.Tc4 = rand.Float64() * 100
			param.Tc5 = rand.Float64() * 100
			param.Tc6 = rand.Float64() * 100
			param.Tc7 = rand.Float64() * 100
			param.Tc8 = rand.Float64() * 100
			param.Tc9 = rand.Float64() * 100
			param.Tc10 = rand.Float64() * 100
			param.Tc11 = rand.Float64() * 100
			param.Tc12 = rand.Float64() * 100
			param.Tc13 = rand.Float64() * 100
			param.Tc14 = rand.Float64() * 100
			param.Tc15 = rand.Float64() * 100
			param.Tc16 = rand.Float64() * 100
			param.Tc17 = rand.Float64() * 100
			param.Tc18 = rand.Float64() * 100
			param.Tc19 = rand.Float64() * 100
			param.Tc20 = rand.Float64() * 100
			param.Tc21 = rand.Float64() * 100
			param.Tc22 = rand.Float64() * 100
			param.Tc23 = rand.Float64() * 100
			param.Tc24 = rand.Float64() * 100
			param.Tc25 = rand.Float64() * 100
			param.Tc26 = rand.Float64() * 100
			param.Tc27 = rand.Float64() * 100
			param.Tc28 = rand.Float64() * 100
			param.Tc29 = rand.Float64() * 100
			param.Tc30 = rand.Float64() * 100
			param.Tc31 = rand.Float64() * 100
			param.Tc32 = rand.Float64() * 100
			param.Tc33 = rand.Float64() * 100
			param.Tc34 = rand.Float64() * 100
			param.Tc35 = rand.Float64() * 100
			param.Tc36 = rand.Float64() * 100
			param.Tc37 = rand.Float64() * 100
			param.Tc38 = rand.Float64() * 100
			param.Tc39 = rand.Float64() * 100
			param.Tc40 = rand.Float64() * 100
			param.Tc41 = rand.Float64() * 100
			param.Tc42 = rand.Float64() * 100
			param.Tc43 = rand.Float64() * 100
			param.Tc44 = rand.Float64() * 100
			param.Tc45 = rand.Float64() * 100
			param.Tc46 = rand.Float64() * 100
			param.Tc47 = rand.Float64() * 100
			param.Tc48 = rand.Float64() * 100
			param.Tc49 = rand.Float64() * 100
			param.Tc50 = rand.Float64() * 100
			param.Tc51 = rand.Float64() * 100
			param.Tc52 = rand.Float64() * 100
			param.Tc53 = rand.Float64() * 100
			param.Tc54 = rand.Float64() * 100
			param.Tc55 = rand.Float64() * 100
			param.Tc56 = rand.Float64() * 100
			param.Tc57 = rand.Float64() * 100
			param.Tc58 = rand.Float64() * 100
			param.Tc59 = rand.Float64() * 100
			param.Tc60 = rand.Float64() * 100
			param.Tc61 = rand.Float64() * 100
			param.Tc62 = rand.Float64() * 100
			param.Tc63 = rand.Float64() * 100
			param.Tc64 = rand.Float64() * 100
			param.Tc65 = rand.Float64() * 100
			param.Tc66 = rand.Float64() * 100
			param.Tc67 = rand.Float64() * 100
			param.Tc68 = rand.Float64() * 100
			param.Tc69 = rand.Float64() * 100
			param.Tc70 = rand.Float64() * 100
			param.Tc71 = rand.Float64() * 100
			param.Tc72 = rand.Float64() * 100
			param.Tc73 = rand.Float64() * 100
			param.Tc74 = rand.Float64() * 100
			param.Tc75 = rand.Float64() * 100
			param.Tc76 = rand.Float64() * 100
			param.Tc77 = rand.Float64() * 100
			param.Tc78 = rand.Float64() * 100
			param.Tc79 = rand.Float64() * 100
			param.Tc80 = rand.Float64() * 100
			param.Tc81 = rand.Float64() * 100
			param.Tc82 = rand.Float64() * 100
			param.Tc83 = rand.Float64() * 100
			param.Tc84 = rand.Float64() * 100
			param.Tc85 = rand.Float64() * 100
			param.Tc86 = rand.Float64() * 100
			param.Tc87 = rand.Float64() * 100
			param.Tc88 = rand.Float64() * 100
			param.Tc89 = rand.Float64() * 100
			param.Tc90 = rand.Float64() * 100
			param.Tc91 = rand.Float64() * 100
			param.Tc92 = rand.Float64() * 100
			param.Tc93 = rand.Float64() * 100
			param.Tc94 = rand.Float64() * 100
			param.Tc95 = rand.Float64() * 100
			param.Tc96 = rand.Float64() * 100
			param.Tc97 = rand.Float64() * 100
			param.Tc98 = rand.Float64() * 100
			param.Tc99 = rand.Float64() * 100
			param.Tc100 = rand.Float64() * 100
			param.Vc1 = rand.Float64() * 100
			param.Vc2 = rand.Float64() * 100
			param.Vc3 = rand.Float64() * 100
			param.Vc4 = rand.Float64() * 100
			param.Vc5 = rand.Float64() * 100
			param.Vc6 = rand.Float64() * 100
			param.Vc7 = rand.Float64() * 100
			param.Vc8 = rand.Float64() * 100
			param.Vc9 = rand.Float64() * 100
			param.Vc10 = rand.Float64() * 100
			param.Vc11 = rand.Float64() * 100
			param.Vc12 = rand.Float64() * 100
			param.Vc13 = rand.Float64() * 100
			param.Vc14 = rand.Float64() * 100
			param.Vc15 = rand.Float64() * 100
			param.Vc16 = rand.Float64() * 100
			param.Vc17 = rand.Float64() * 100
			param.Vc18 = rand.Float64() * 100
			param.Vc19 = rand.Float64() * 100
			param.Vc20 = rand.Float64() * 100
			param.Vc21 = rand.Float64() * 100
			param.Vc22 = rand.Float64() * 100
			param.Vc23 = rand.Float64() * 100
			param.Vc24 = rand.Float64() * 100
			param.Vc25 = rand.Float64() * 100
			param.Vc26 = rand.Float64() * 100
			param.Vc27 = rand.Float64() * 100
			param.Vc28 = rand.Float64() * 100
			param.Vc29 = rand.Float64() * 100
			param.Vc30 = rand.Float64() * 100
			param.Vc31 = rand.Float64() * 100
			param.Vc32 = rand.Float64() * 100
			param.Vc33 = rand.Float64() * 100
			param.Vc34 = rand.Float64() * 100
			param.Vc35 = rand.Float64() * 100
			param.Vc36 = rand.Float64() * 100
			param.Vc37 = rand.Float64() * 100
			param.Vc38 = rand.Float64() * 100
			param.Vc39 = rand.Float64() * 100
			param.Vc40 = rand.Float64() * 100
			param.Vc41 = rand.Float64() * 100
			param.Vc42 = rand.Float64() * 100
			param.Vc43 = rand.Float64() * 100
			param.Vc44 = rand.Float64() * 100
			param.Vc45 = rand.Float64() * 100
			param.Vc46 = rand.Float64() * 100
			param.Vc47 = rand.Float64() * 100
			param.Vc48 = rand.Float64() * 100
			param.Vc49 = rand.Float64() * 100
			param.Vc50 = rand.Float64() * 100
			param.Vc51 = rand.Float64() * 100
			param.Vc52 = rand.Float64() * 100
			param.Vc53 = rand.Float64() * 100
			param.Vc54 = rand.Float64() * 100
			param.Vc55 = rand.Float64() * 100
			param.Vc56 = rand.Float64() * 100
			param.Vc57 = rand.Float64() * 100
			param.Vc58 = rand.Float64() * 100
			param.Vc59 = rand.Float64() * 100
			param.Vc60 = rand.Float64() * 100
			param.Vc61 = rand.Float64() * 100
			param.Vc62 = rand.Float64() * 100
			param.Vc63 = rand.Float64() * 100
			param.Vc64 = rand.Float64() * 100
			param.Vc65 = rand.Float64() * 100
			param.Vc66 = rand.Float64() * 100
			param.Vc67 = rand.Float64() * 100
			param.Vc68 = rand.Float64() * 100
			param.Vc69 = rand.Float64() * 100
			param.Vc70 = rand.Float64() * 100
			param.Vc71 = rand.Float64() * 100
			param.Vc72 = rand.Float64() * 100
			param.Vc73 = rand.Float64() * 100
			param.Vc74 = rand.Float64() * 100
			param.Vc75 = rand.Float64() * 100
			param.Vc76 = rand.Float64() * 100
			param.Vc77 = rand.Float64() * 100
			param.Vc78 = rand.Float64() * 100
			param.Vc79 = rand.Float64() * 100
			param.Vc80 = rand.Float64() * 100
			param.Vc81 = rand.Float64() * 100
			param.Vc82 = rand.Float64() * 100
			param.Vc83 = rand.Float64() * 100
			param.Vc84 = rand.Float64() * 100
			param.Vc85 = rand.Float64() * 100
			param.Vc86 = rand.Float64() * 100
			param.Vc87 = rand.Float64() * 100
			param.Vc88 = rand.Float64() * 100
			param.Vc89 = rand.Float64() * 100
			param.Vc90 = rand.Float64() * 100
			param.Vc91 = rand.Float64() * 100
			param.Vc92 = rand.Float64() * 100
			param.Vc93 = rand.Float64() * 100
			param.Vc94 = rand.Float64() * 100
			param.Vc95 = rand.Float64() * 100
			param.Vc96 = rand.Float64() * 100
			param.Vc97 = rand.Float64() * 100
			param.Vc98 = rand.Float64() * 100
			param.Vc99 = rand.Float64() * 100
			param.Vc100 = rand.Float64() * 100

			param.CreateTime = model.LocalTime(time.Now())
			err := model.DB.Create(&param).Error
			if err != nil {
				fmt.Println("GenerateData sql error:", err.Error())
				Task1.FailTimes++
				Task1.LastError = err.Error()
				continue
			}
		}
		Task1.SuccessTimes++
		time.Sleep(time.Duration(Task1.Interval) * time.Second)
	}
}
